BookController.php 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749
  1. <?php
  2. namespace App\Http\Controllers\Manage\Book;
  3. use App\Http\Controllers\Controller;
  4. use App\Http\Controllers\Manage\Book\Transformers\BookTransformer;
  5. use App\Http\Controllers\Manage\Book\Transformers\SmartPushBookTransformer;
  6. use App\Modules\Book\Models\Book;
  7. use App\Modules\Book\Models\BookConfig;
  8. use App\Modules\Book\Services\BookConfigService;
  9. use App\Modules\Book\Services\BookService;
  10. use App\Modules\Book\Services\BookSpecialChannelService;
  11. use App\Modules\Book\Services\BookTagsService;
  12. use App\Modules\Channel\Services\ChannelService;
  13. use App\Modules\Statistic\Services\WapVisitStatService;
  14. use App\Modules\Product\Services\ProductService;
  15. use DB;
  16. use Hashids;
  17. use Cache;
  18. use Illuminate\Http\Request;
  19. use OSS\Core\OssException;
  20. use OSS\OssClient;
  21. use Redis;
  22. use Storage;
  23. class BookController extends Controller
  24. {
  25. /**
  26. * @apiDefine Book 图书模块
  27. */
  28. /**
  29. * @apiVersion 1.0.0
  30. * @apiDescription 按bid获取图书详情
  31. * @api {get} book/{bid} 获取图书详情
  32. * @apiGroup Book
  33. * @apiName getBookById
  34. * @apiSuccess {int} code 状态码
  35. * @apiSuccess {String} msg 信息
  36. * @apiSuccess {object} data 结果集
  37. * @apiSuccess {Int} data.book_id bid
  38. * @apiSuccess {String} data.book_name 书名
  39. * @apiSuccess {String} data.book_summary 简介
  40. * @apiSuccess {String} data.book_author 作者
  41. * @apiSuccess {String} data.cover_url 封面
  42. * @apiSuccess {Int} data.book_word_count 字数
  43. * @apiSuccess {Int} data.book_chapter_total 章节数
  44. * @apiSuccess {Int} data.book_category_id 分类
  45. * @apiSuccess {String} data.book_category 分类名
  46. * @apiSuccess {Int} data.book_end_status 是否完结
  47. * @apiSuccess {String} data.book_published_time 发布时间
  48. * @apiSuccess {String} data.copyright 版权信息
  49. * @apiSuccess {Int} data.force_subscribe_chapter_id 强制关注的章节数
  50. * @apiSuccess {String} data.update_time 更新时间
  51. * @apiSuccess {Int} data.is_on_shelf 是否上架
  52. * @apiSuccess {Int} data.book_price 价格
  53. * @apiSuccess {String} data.charge_type 收费类型
  54. * @apiSuccess {String} data.keyword 关键词
  55. * @apiSuccess {String} data.recommend_index 推荐指数
  56. * @apiSuccess {String} data.is_show_index_content 是否显示推荐指数文本
  57. * @apiSuccess {Int} data.click_count 点击数
  58. * @apiSuccess {Int} data.product_id product_id
  59. * @apiSuccess {Int} data.sex_preference 性别偏象
  60. * @apiSuccess {Int} data.last_cid 最后一章id
  61. * @apiSuccess {Int} data.last_chapter 最后一章名
  62. * @apiSuccess {Int} data.first_cid 第一章cid
  63. * @apiSuccess {String} data.old_name 旧书名
  64. * @apiSuccess {String} data.recommend_text 推广标题
  65. * @apiSuccess {String} data.is_high_quality 是否优质
  66. * @apiSuccessExample {json} Success-Response:
  67. * HTTP/1.1 200 OK
  68. * {
  69. * code: 0,
  70. * msg: "",
  71. * data: {
  72. * book_id: 5,
  73. * book_name: "肌缘巧合",
  74. * book_summary: "&nbsp;&nbsp;&nbsp;&nbsp;他是权势倾天,纵横商界的王者,却偏偏钟情于她,一宠成瘾。“女人,我要你......只要你能满足我,别墅、游轮、支票,你随便挑。”她羞涩的半低着头:“我只想要你。”他挑眉,“你野心不小啊!”她妩媚一笑,解开他的领带,“难道你不愿意!”他宠她爱她,给她所有想要的。只是有一天她终于忍不住暴走,“靠,你有没有节制呀?我要离婚。”",
  75. * book_author: "妖火",
  76. * cover_url: "http://www.leyuee.com/cover/0/8.jpg",
  77. * book_word_count: 0,
  78. * book_chapter_total: 0,
  79. * book_category_id: null,
  80. * book_category: "爆笑,宠文,潜规则",
  81. * book_end_status: 8,
  82. * book_published_time: null,
  83. * copyright: null,
  84. * charge_type: null,
  85. * force_subscribe_chapter_id: 0,
  86. * update_time: null,
  87. * is_on_shelf: 0,
  88. * book_price: null,
  89. * keyword: 关键词,
  90. * recommend_index:2,
  91. * is_show_index_content:0,
  92. * click_count:0,
  93. * product_id:0,
  94. * sex_preference:0,
  95. * last_cid:0
  96. * last_chapter:hello
  97. * }
  98. * }
  99. */
  100. public function getBookById($bid)
  101. {
  102. $res = BookConfigService::getBookById($bid);
  103. $content = '';
  104. if (Storage::exists('RecommendChapterPositionWord.txt')) {
  105. $content = Storage::get('RecommendChapterPositionWord.txt');
  106. } else {
  107. $content = '建议此章节生成推广文案(原文转化率好)';
  108. }
  109. $res->recommend_text = $content;
  110. return response()->item(new BookTransformer(), $res);
  111. }
  112. /**
  113. * @apiVersion 1.0.0
  114. * @apiDescription 修改上架状态 0下架 0
  115. * @api {get} books/shelf/status 上架图书
  116. * @apiParam {int} on_shelf_status
  117. * @apiParam {int} bid
  118. * @apiGroup Book
  119. * @apiName changeShelfStatus
  120. * @apiSuccess {int} code 状态码
  121. * @apiSuccess {String} msg 信息
  122. * @apiSuccess {object} data 结果集
  123. * @apiSuccessExample {json} Success-Response:
  124. * HTTP/1.1 200 OK
  125. * {
  126. * code: 0,
  127. * msg: "",
  128. * data: {}
  129. * }
  130. */
  131. public function changeShelfStatus(Request $request)
  132. {
  133. $bid = $request->input('bid');
  134. $shelf_status = $request->input('on_shelf_status');
  135. if (!in_array($shelf_status, [0, 1, 2, 3])) response()->error('PARAM_EMPTY');
  136. if (empty($bid)) return response()->error('PARAM_EMPTY');
  137. $data = ['is_on_shelf' => $shelf_status];
  138. if ($shelf_status == 1) {
  139. $off_shelf_domain = env('OFF_SHELF_DOMAIN');
  140. if ($off_shelf_domain) {
  141. $data['promotion_domain'] = $off_shelf_domain;
  142. }
  143. }
  144. if (BookConfigService::updateBookConfig($bid, $data)) {
  145. return response()->success();
  146. } else {
  147. return response()->error('PARAM_ERROR');
  148. }
  149. }
  150. /**
  151. * @apiVersion 1.0.0
  152. * @apiDescription 编辑图书
  153. * @api {post} books/{bid}/edit 编辑图书
  154. * @apiName editBookConfig
  155. * @apiParam {Int} force_subscribe_chapter_seq 强制关注的章节数(非必需)
  156. * @apiParam {Int} price 图书价格(单位:分)(非必需)
  157. * @apiParam {String} cover 封面(非必需)
  158. * @apiParam {String} book_name 书名(非必需)
  159. * @apiParam {String} copyright 版权说明(非必需)
  160. * @apiParam {String} charge_type 收费类型 按本、按章CHAPTER、BOOK(非必需)
  161. * @apiParam {Int} hot 热度(非必需)
  162. * @apiParam {Int} is_on_shelf 是否上架 1:上架 0:不上架(非必需)
  163. * @apiParam {Int} is_on_shelf 是否上架 1:上架 0:不上架(非必需)
  164. * @apiParam {String} source_domain 来源域名(非必需)
  165. * @apiParam {Int} is_show_index_content 是否推荐指数文本
  166. * @apiParam {Int} product_id product_id
  167. * @apiGroup Book
  168. * @apiSuccess {Int} code 状态码
  169. * @apiSuccess {String} msg 信息
  170. * @apiSuccess {object} data 结果集
  171. * @apiSuccessExample {json} Success-Response:
  172. * HTTP/1.1 200 OK
  173. * {
  174. * code: 0,
  175. * msg: "",
  176. * data: {}
  177. * }
  178. */
  179. public function editBookConfig(Request $request, $bid)
  180. {
  181. if (empty($bid)) return response()->error('PARAM_EMPTY');
  182. //$bid = $request->input('bid');
  183. $force_subscribe_chapter_seq = $request->input('force_subscribe_chapter_seq');
  184. $price = $request->input('price');
  185. $cover = $request->input('cover');
  186. $book_name = $request->input('book_name');
  187. $copyright = $request->input('copyright');
  188. $charge_type = $request->input('charge_type');
  189. $hot = $request->input('hot');
  190. $roles = $request->input('roles');
  191. $is_on_shelf = $request->input('is_on_shelf');
  192. $source_domain = $request->input('source_domain');
  193. $promotion_domain = $request->input('promotion_domain');
  194. $recommend_index = $request->input('recommend_index');
  195. $is_show_index_content = $request->input('is_show_index_content');
  196. $product_id = $request->input('product_id');
  197. $status = $request->input('status');
  198. $book_category_id = $request->input('book_category_id');
  199. $data = [];
  200. if (isset($force_subscribe_chapter_seq) && $force_subscribe_chapter_seq !== '') $data['force_subscribe_chapter_seq'] = $force_subscribe_chapter_seq;
  201. if (isset($price) && !empty($price)) $data['price'] = $price;
  202. if (isset($cover) && !empty($cover)) $data['cover'] = $cover;
  203. if (isset($book_name) && !empty($book_name)) $data['book_name'] = $book_name;
  204. if (isset($copyright) && !empty($copyright)) $data['copyright'] = $copyright;
  205. if (isset($charge_type) && !empty($charge_type)) $data['charge_type'] = $charge_type;
  206. if (isset($hot) && !empty($hot)) $data['hot'] = $hot;
  207. if (isset($roles) && !empty($roles)) $data['roles'] = $roles;
  208. if (isset($is_on_shelf) && $is_on_shelf !== '') $data['is_on_shelf'] = (int)$is_on_shelf;
  209. if (isset($source_domain) && !empty($source_domain)) $data['source_domain'] = $source_domain;
  210. if (isset($recommend_index) && $recommend_index !== '') $data['recommend_index'] = $recommend_index;
  211. if (isset($is_show_index_content)) $data['is_show_index_content'] = (int)$is_show_index_content;
  212. if (isset($product_id) && $product_id !== '') $data['product_id'] = (int)$product_id;
  213. if (isset($status) && $status !== '') $data['status'] = (int)$status;
  214. if (isset($book_category_id) && $book_category_id != '') $data['book_category_id'] = (int)$book_category_id;
  215. if (isset($promotion_domain) && $promotion_domain != '') $data['promotion_domain'] = $promotion_domain;
  216. if (empty($data)) return response()->error('PARAM_EMPTY');
  217. if (BookConfigService::updateBookConfig($bid, $data)) {
  218. return response()->success();
  219. }
  220. return response()->error('UNKNOWN_ERROR');
  221. }
  222. /**
  223. * @apiVersion 1.0.0
  224. * @apiDescription 编辑版权信息
  225. * @api {post} books/editcopyright 编辑版权信息
  226. * @apiName editCopyRight
  227. * @apiParam {Int} bid 图书id
  228. * @apiParam {String} [copyright_limit_data] 版权截至日期
  229. * @apiParam {String} [copyright] 版权说明
  230. * @apiGroup Book
  231. * @apiSuccess {Int} code 状态码
  232. * @apiSuccess {String} msg 信息
  233. * @apiSuccess {object} data 结果集
  234. * @apiSuccessExample {json} Success-Response:
  235. * HTTP/1.1 200 OK
  236. * {
  237. * code: 0,
  238. * msg: "",
  239. * data: {}
  240. * }
  241. */
  242. public function editCopyRight(Request $request)
  243. {
  244. $bid = $request->input('bid');
  245. if (empty($bid)) return response()->error('PARAM_EMPTY');
  246. $copyright = $request->input('copyright');
  247. $copyright_limit_data = $request->input('copyright_limit_data');
  248. if (isset($copyright)) {
  249. $data['copyright'] = $copyright;
  250. }
  251. if (isset($copyright_limit_data)) {
  252. $data['copyright_limit_data'] = $copyright_limit_data;
  253. }
  254. if (empty($data)) return response()->error('PARAM_EMPTY');
  255. if (BookConfigService::updateBookConfig($bid, $data)) {
  256. return response()->success();
  257. }
  258. return response()->error('UNKNOWN_ERROR');
  259. }
  260. /**
  261. * @apiVersion 1.0.0
  262. * @apiDescription 编辑图书域名
  263. * @api {post} books/editPromotionUrl 编辑图书域名
  264. * @apiName editPromotionDomain
  265. * @apiParam {Int} bid 图书id
  266. * @apiParam {String} promotion_domain 图书域名多个以都好隔开
  267. * @apiGroup Book
  268. * @apiSuccess {Int} code 状态码
  269. * @apiSuccess {String} msg 信息
  270. * @apiSuccess {object} data 结果集
  271. * @apiSuccessExample {json} Success-Response:
  272. * HTTP/1.1 200 OK
  273. * {
  274. * code: 0,
  275. * msg: "",
  276. * data: {}
  277. * }
  278. */
  279. public function editPromotionDomain(Request $request)
  280. {
  281. $bid = $request->input('bid');
  282. if (empty($bid)) return response()->error('PARAM_EMPTY');
  283. $promotion_domain = $request->input('promotion_domain');
  284. if (isset($promotion_domain)) {
  285. $data['promotion_domain'] = $promotion_domain;
  286. }
  287. if (empty($data)) return response()->error('PARAM_EMPTY');
  288. if (BookConfigService::updateBookConfig($bid, $data)) {
  289. return response()->success();
  290. }
  291. return response()->error('UNKNOWN_ERROR');
  292. }
  293. /**
  294. * @apiVersion 1.0.0
  295. * @apiDescription 根据分类id和关键词获取并按照推荐指数排序
  296. * @api {get} books/search 图书搜索
  297. * @apiParam {String} key
  298. * @apiParam {Int} category_id 分类id
  299. * @apiParam {String} [domain] 域名 按域名查询
  300. * @apiParam {String} [old_name] 旧书名 按旧书名查询
  301. * @apiParam {String} [copy_right_date] 版权到期时间
  302. * @apiParam {String} order_field 排序字段(推荐指数:recommend_index|点击数:click_count|字数:size|update:时间)
  303. * @apiParam {String} order_seq 排序顺序(顺序:asc|逆序:desc)
  304. * @apiParam {Int} is_on_shelf 上架与否(0|1)
  305. * @apiParam {Int} page_size 分页大小
  306. * @apiParam {Int} status 完结与否(0|1)
  307. * @apiGroup Book
  308. * @apiName getBooksByWhere
  309. * @apiSuccess {int} code 状态码
  310. * @apiSuccess {String} msg 信息
  311. * @apiSuccess {object} data 结果集
  312. * @apiSuccess {Array} data.list 结果数据集
  313. * @apiSuccess {Int} data.list.book_id bid
  314. * @apiSuccess {String} data.list.book_name 书名
  315. * @apiSuccess {String} data.list.book_summary 简介
  316. * @apiSuccess {String} data.list.book_author 作者
  317. * @apiSuccess {String} data.list.cover_url 封面
  318. * @apiSuccess {Int} data.list.book_word_count 字数
  319. * @apiSuccess {Int} data.list.book_chapter_total 章节数
  320. * @apiSuccess {Int} data.list.book_category_id 分类
  321. * @apiSuccess {String} data.list.book_category 分类名
  322. * @apiSuccess {String} data.list.book_end_status 是否完结
  323. * @apiSuccess {String} data.list.book_published_time 发布时间
  324. * @apiSuccess {String} data.list.copyright 版权信息
  325. * @apiSuccess {Int} data.list.force_subscribe_chapter_id 强制关注的章节数
  326. * @apiSuccess {String} data.list.update_time 更新时间
  327. * @apiSuccess {Int} data.list.is_on_shelf 是否上架
  328. * @apiSuccess {String} data.list.book_price 是否上架
  329. * @apiSuccess {String} data.list.recommend_index 推荐指数
  330. * @apiSuccess {Int} data.list.charge_type 收费类型
  331. * @apiSuccess {Int} data.list.keyword 关键词
  332. * @apiSuccess {Int} data.list.is_show_index_content 是否显示推荐指数文本
  333. * @apiSuccess {Int} data.list.click_count 点击数
  334. * @apiSuccess {Int} data.list.product_id product_id
  335. * @apiSuccess {Int} data.list.sex_preference 性格偏向
  336. * @apiSuccess {Int} data.list.last_cid 最后一章id
  337. * @apiSuccess {Int} data.list.last_chapter 最后一章名
  338. * @apiSuccess {String} data.list.old_name 旧书名
  339. * @apiSuccess {object} data.meta 分页信息
  340. * @apiSuccess {Int} data.meta.total 总条数
  341. * @apiSuccess {Int} data.meta.per_page 每页条数
  342. * @apiSuccess {Int} data.meta.current_page 当前页
  343. * @apiSuccess {Int} data.meta.last_page 最后页
  344. * @apiSuccess {String} data.meta.next_page_url 下一页
  345. * @apiSuccess {String} data.meta.prev_page_url 上一页
  346. * @apiSuccess {String} data.list.is_high_quality 是否优质
  347. * @apiSuccessExample {json} Success-Response:
  348. * HTTP/1.1 200 OK
  349. * {
  350. * code: 0,
  351. * msg: "",
  352. * data: {
  353. * list: [
  354. * {
  355. * book_id: 5,
  356. * book_name: "肌缘巧合",
  357. * book_summary: "&nbsp;&nbsp;&nbsp;&nbsp;他是权势倾天,纵横商界的王者,却偏偏钟情于她,一宠成瘾。“女人,我要你......只要你能满足我,别墅、游轮、支票,你随便挑。”她羞涩的半低着头:“我只想要你。”他挑眉,“你野心不小啊!”她妩媚一笑,解开他的领带,“难道你不愿意!”他宠她爱她,给她所有想要的。只是有一天她终于忍不住暴走,“靠,你有没有节制呀?我要离婚。”",
  358. * book_author: "妖火",
  359. * cover_url: "http://www.leyuee.com/cover/0/8.jpg",
  360. * book_word_count: 0,
  361. * book_chapter_total: 0,
  362. * book_category_id: null,
  363. * book_category: "爆笑,宠文,潜规则",
  364. * book_end_status: 8,
  365. * book_published_time: null,
  366. * copyright: null,
  367. * charge_type: null,
  368. * force_subscribe_chapter_id: 0,
  369. * update_time: null,
  370. * is_on_shelf: 1,
  371. * book_price: null,
  372. * keyword: "温馨,虐心,清水",
  373. * recommend_index:2,
  374. * is_show_index_content:0,
  375. * click_count:0,
  376. * product_id:0,
  377. * sex_preference:0,
  378. * last_cid:0,
  379. * last_chapter:0,
  380. * },
  381. * ],
  382. * meta: {
  383. * total: 18,
  384. * per_page: 15,
  385. * current_page: 1,
  386. * last_page: 2,
  387. * next_page_url: "http://myapi.cn/api/hotrank/books?page=2",
  388. * prev_page_url: ""
  389. * }
  390. * }
  391. * }
  392. */
  393. public function getBooksByWhere(Request $request)
  394. {
  395. $where = [];
  396. $order = ['book_configs.id', 'asc'];
  397. $where['is_on_shelf'] = [1, 2];
  398. $category_id = $request->input('category_id');
  399. if ($category_id) {
  400. if ($category_id == 1) {
  401. $where['channel_name'] = '男频';
  402. } elseif ($category_id == 2) {
  403. $where['channel_name'] = '女频';
  404. } else {
  405. $where['category_id'] = $category_id;
  406. }
  407. }
  408. $old_name = $request->input('old_name');
  409. $domain = $request->input('domain');
  410. $copy_right_date = $request->input('copy_right_date');
  411. $bid = $request->input('bid');
  412. if ($bid) $where['bid'] = $bid;
  413. if ($old_name) $where['old_name'] = $old_name;
  414. if ($domain) $where['domain'] = $domain;
  415. if ($copy_right_date) $where['copy_right_date'] = $copy_right_date;
  416. $author = $request->input('author');
  417. if ($author) $where['author'] = $author;
  418. $key = $request->input('key');
  419. if ($key) {
  420. $where['key'] = $key;
  421. }
  422. $order_field = $request->input('order_field');
  423. $order_seq = $request->input('order_seq');
  424. if ($order_field != '' && in_array($order_field, ['recommend_index', 'click_count', 'update', 'size', 'create'])) {
  425. if ($order_field == 'update') {
  426. $order = ['book_configs.updated_at', 'desc'];
  427. } elseif ($order_field == 'create') {
  428. $order = ['book_configs.created_at', 'desc'];
  429. } else {
  430. $order = [$order_field, 'desc'];
  431. }
  432. if ($order_seq == 'asc') {
  433. $order = [$order_field, 'asc'];
  434. }
  435. if ($order_seq == 'desc') {
  436. $order = [$order_field, 'desc'];
  437. }
  438. }
  439. $status = $request->input('status');
  440. if ($status != '') {
  441. $where['status'] = $status;
  442. }
  443. $page_size = $request->input('page_size', 15);
  444. $books = BookConfigService::getBooks($where, $order, $page_size);
  445. return response()->pagination(new BookTransformer, $books);
  446. }
  447. public function getBooks(Request $request)
  448. {
  449. $book_name = $request->has('book_name') ? $request->input('book_name') : '';
  450. $is_important = $request->has('is_important') ? $request->input('is_important') : 0;
  451. if (1 == $is_important) {
  452. $where['is_on_shelf'] = [1, 2];
  453. } else {
  454. $where['is_on_shelf'] = [2];
  455. }
  456. $data = DB::table('book_configs')->select('book_name', 'bid')->where('book_name', 'like', '%' . $book_name . '%')->whereIn('is_on_shelf', $where)->get();
  457. return response()->success($data);
  458. }
  459. /**
  460. * @apiVersion 1.0.0
  461. * @apiDescription 获取下架图书
  462. * @api {get} offshelf/books 获取下架图书
  463. * @apiParam {Int} [page_size] 分页大小
  464. * @apiParam {String} [domain] 域名 按域名查询
  465. * @apiParam {String} [old_name] 旧书名 按旧书名查询
  466. * @apiParam {String} [copy_right_date] 版权到期时间
  467. * @apiParam {Int} [page] 页码
  468. * @apiGroup Book
  469. * @apiName getOffShelfBooks
  470. * @apiSuccess {int} code 状态码
  471. * @apiSuccess {String} msg 信息
  472. * @apiSuccess {object} data 结果集
  473. * @apiSuccess {Array} data 结果数据集
  474. * @apiSuccess {Int} data.book_id bid
  475. * @apiSuccess {String} data.book_name 书名
  476. * @apiSuccess {String} data.book_summary 简介
  477. * @apiSuccess {String} data.book_author 作者
  478. * @apiSuccess {String} data.cover_url 封面
  479. * @apiSuccess {Int} data.book_word_count 字数
  480. * @apiSuccess {Int} data.book_chapter_total 章节数
  481. * @apiSuccess {Int} data.book_category_id 分类
  482. * @apiSuccess {String} data.book_category 分类名
  483. * @apiSuccess {String} data.book_end_status 是否完结
  484. * @apiSuccess {String} data.book_published_time 发布时间
  485. * @apiSuccess {String} data.copyright 版权信息
  486. * @apiSuccess {Int} data.force_subscribe_chapter_id 强制关注的章节数
  487. * @apiSuccess {String} data.update_time 更新时间
  488. * @apiSuccess {Int} data.is_on_shelf 是否上架
  489. * @apiSuccess {String} data.book_price 是否上架
  490. * @apiSuccess {String} data.recommend_index 推荐指数
  491. * @apiSuccess {Int} data.charge_type 收费类型
  492. * @apiSuccess {Int} data.keyword 关键词
  493. * @apiSuccess {Int} data.is_show_index_content 是否显示推荐指数文本
  494. * @apiSuccess {Int} data.click_count 点击数
  495. * @apiSuccess {Int} data.product_id product_id
  496. * @apiSuccess {Int} data.sex_preference 性格偏向
  497. * @apiSuccess {String} data.old_name 旧书名
  498. * @apiSuccess {String} data.is_high_quality 是否优质
  499. * @apiSuccessExample {json} Success-Response:
  500. * HTTP/1.1 200 OK
  501. * {
  502. * code: 0,
  503. * msg: "",
  504. * data: {
  505. * [
  506. * {
  507. * book_id: 5,
  508. * book_name: "肌缘巧合",
  509. * book_summary: "&nbsp;&nbsp;&nbsp;&nbsp;他是权势倾天,纵横商界的王者,却偏偏钟情于她,一宠成瘾。“女人,我要你......只要你能满足我,别墅、游轮、支票,你随便挑。”她羞涩的半低着头:“我只想要你。”他挑眉,“你野心不小啊!”她妩媚一笑,解开他的领带,“难道你不愿意!”他宠她爱她,给她所有想要的。只是有一天她终于忍不住暴走,“靠,你有没有节制呀?我要离婚。”",
  510. * book_author: "妖火",
  511. * cover_url: "http://www.leyuee.com/cover/0/8.jpg",
  512. * book_word_count: 0,
  513. * book_chapter_total: 0,
  514. * book_category_id: null,
  515. * book_category: "爆笑,宠文,潜规则",
  516. * book_end_status: 8,
  517. * book_published_time: null,
  518. * copyright: null,
  519. * charge_type: null,
  520. * force_subscribe_chapter_id: 0,
  521. * update_time: null,
  522. * is_on_shelf: 1,
  523. * book_price: null,
  524. * keyword: "温馨,虐心,清水",
  525. * recommend_index:2,
  526. * is_show_index_content:0,
  527. * click_count:0,
  528. * product_id:0,
  529. * sex_preference:0,
  530. * },
  531. * {}
  532. * ],
  533. * meta:{}
  534. * }
  535. * }
  536. */
  537. public function getOffShelfBooks(Request $request)
  538. {
  539. $where = ['is_on_shelf' => [0]];
  540. $key = $request->input('key');
  541. $author = $request->input('author');
  542. if ($author) $where['author'] = $author;
  543. if ($key) $where['key'] = $key;
  544. $category_id = $request->input('category_id');
  545. if ($category_id) {
  546. if ($category_id == 1) {
  547. $where['channel_name'] = '男频';
  548. } elseif ($category_id == 2) {
  549. $where['channel_name'] = '女频';
  550. } else {
  551. $where['category_id'] = $category_id;
  552. }
  553. }
  554. $old_name = $request->input('old_name');
  555. $domain = $request->input('domain');
  556. $copy_right_date = $request->input('copy_right_date');
  557. $bid = $request->input('bid');
  558. if ($bid) $where['bid'] = $bid;
  559. if ($old_name) $where['old_name'] = $old_name;
  560. if ($domain) $where['domain'] = $domain;
  561. if ($copy_right_date) $where['copy_right_date'] = $copy_right_date;
  562. $page_size = $request->input('page_size', 15);
  563. $res = BookConfigService::getBooks($where, [], $page_size);
  564. foreach ($res as &$item) {
  565. $item->book_special_channels = [];
  566. $channels = BookSpecialChannelService::getChannelsByBid($item->bid);
  567. if ($channels) {
  568. $channel_array = [];
  569. foreach ($channels as $channel) {
  570. $channel_array[] = $channel->channel_user_id;
  571. }
  572. $item->book_special_channels = $channel_array;
  573. }
  574. }
  575. return response()->pagination(new BookTransformer, $res);
  576. }
  577. /**
  578. * @apiVersion 1.0.0
  579. * @apiDescription 获取上架架图书
  580. * @api {get} onshelf/books 获取上架架图书
  581. * @apiParam {Int} [page_size] 分页大小
  582. * @apiParam {Int} [page] 页码
  583. * @apiParam {String} [domain] 域名 按域名查询
  584. * @apiParam {String} [old_name] 旧书名 按旧书名查询
  585. * @apiParam {String} [copy_right_date] 版权到期时间
  586. * @apiParam {Int} [type] 1:内部上架,2外部上架
  587. * @apiGroup Book
  588. * @apiName getOnShelfBooks
  589. * @apiSuccess {int} code 状态码
  590. * @apiSuccess {String} msg 信息
  591. * @apiSuccess {object} data 结果集
  592. * @apiSuccess {Array} data 结果数据集
  593. * @apiSuccess {Int} data.book_id bid
  594. * @apiSuccess {String} data.book_name 书名
  595. * @apiSuccess {String} data.book_summary 简介
  596. * @apiSuccess {String} data.book_author 作者
  597. * @apiSuccess {String} data.cover_url 封面
  598. * @apiSuccess {Int} data.book_word_count 字数
  599. * @apiSuccess {Int} data.book_chapter_total 章节数
  600. * @apiSuccess {Int} data.book_category_id 分类
  601. * @apiSuccess {String} data.book_category 分类名
  602. * @apiSuccess {String} data.book_end_status 是否完结
  603. * @apiSuccess {String} data.book_published_time 发布时间
  604. * @apiSuccess {String} data.copyright 版权信息
  605. * @apiSuccess {Int} data.force_subscribe_chapter_id 强制关注的章节数
  606. * @apiSuccess {String} data.update_time 更新时间
  607. * @apiSuccess {Int} data.is_on_shelf 是否上架
  608. * @apiSuccess {String} data.book_price 是否上架
  609. * @apiSuccess {String} data.recommend_index 推荐指数
  610. * @apiSuccess {Int} data.charge_type 收费类型
  611. * @apiSuccess {Int} data.keyword 关键词
  612. * @apiSuccess {Int} data.is_show_index_content 是否显示推荐指数文本
  613. * @apiSuccess {Int} data.click_count 点击数
  614. * @apiSuccess {Int} data.product_id product_id
  615. * @apiSuccess {Int} data.sex_preference 性格偏向
  616. * @apiSuccess {String} data.old_name 旧书名
  617. * @apiSuccess {String} data.is_high_quality 是否优质
  618. * @apiSuccessExample {json} Success-Response:
  619. * HTTP/1.1 200 OK
  620. * {
  621. * code: 0,
  622. * msg: "",
  623. * data: {
  624. * [
  625. * {
  626. * book_id: 5,
  627. * book_name: "肌缘巧合",
  628. * book_summary: "&nbsp;&nbsp;&nbsp;&nbsp;他是权势倾天,纵横商界的王者,却偏偏钟情于她,一宠成瘾。“女人,我要你......只要你能满足我,别墅、游轮、支票,你随便挑。”她羞涩的半低着头:“我只想要你。”他挑眉,“你野心不小啊!”她妩媚一笑,解开他的领带,“难道你不愿意!”他宠她爱她,给她所有想要的。只是有一天她终于忍不住暴走,“靠,你有没有节制呀?我要离婚。”",
  629. * book_author: "妖火",
  630. * cover_url: "http://www.leyuee.com/cover/0/8.jpg",
  631. * book_word_count: 0,
  632. * book_chapter_total: 0,
  633. * book_category_id: null,
  634. * book_category: "爆笑,宠文,潜规则",
  635. * book_end_status: 8,
  636. * book_published_time: null,
  637. * copyright: null,
  638. * charge_type: null,
  639. * force_subscribe_chapter_id: 0,
  640. * update_time: null,
  641. * is_on_shelf: 1,
  642. * book_price: null,
  643. * keyword: "温馨,虐心,清水",
  644. * recommend_index:2,
  645. * is_show_index_content:0,
  646. * click_count:0,
  647. * product_id:0,
  648. * sex_preference:0,
  649. * },
  650. * {}
  651. * ],
  652. * meta:{}
  653. * }
  654. * }
  655. */
  656. public function getOnShelfBooks(Request $request)
  657. {
  658. //\Log::info('setPromotionStatus is: ' ,['param'=>$request->all()]);
  659. $where = ['is_on_shelf' => [1, 2]];
  660. $firstChapterContent = $request->input('firstChapterContent');
  661. $week_promotion = $request->get('weekly_promotion','null');
  662. if(!in_array($week_promotion,[0,1,'0','1','null'])) {
  663. return response()->error('PARAM_ERROR');
  664. }
  665. if($week_promotion != 'null') {
  666. $where['is_current_week_promotion'] = $week_promotion;
  667. }
  668. $type = $request->input('type');
  669. $order = [];
  670. if ($type == 1) {
  671. $where['is_on_shelf'] = 1;
  672. $order = ['book_configs.created_at', 'desc'];
  673. }
  674. if ($type == 2) {
  675. $where['is_on_shelf'] = 2;
  676. }
  677. $author = $request->input('author');
  678. $roles = $request->input('roles');
  679. $tags = $request->input('tags');
  680. if ($author) $where['author'] = $author;
  681. $charge_type = $request->input('charge_type');
  682. if ($charge_type) {
  683. $where['charge_type'] = $charge_type;
  684. }
  685. if($tags){
  686. $where['tags'] = $tags;
  687. }
  688. if ($roles) {
  689. $where['roles'] = $roles;
  690. }
  691. $key = $request->input('key');
  692. if ($key) $where['key'] = $key;
  693. $category_id = $request->input('category_id');
  694. if ($category_id) {
  695. if ($category_id == 1) {
  696. $where['channel_name'] = '男频';
  697. } elseif ($category_id == 2) {
  698. $where['channel_name'] = '女频';
  699. } else {
  700. $where['category_id'] = $category_id;
  701. }
  702. }
  703. if ($firstChapterContent) {
  704. $where['firstChapterContent'] = $firstChapterContent;
  705. }
  706. $old_name = $request->input('old_name');
  707. $domain = $request->input('domain');
  708. $copy_right_date = $request->input('copy_right_date');
  709. $is_high_quality = $request->input('is_high_quality');
  710. if ($is_high_quality != '') {
  711. $where['is_high_quality'] = $is_high_quality;
  712. }
  713. $bid = $request->input('bid');
  714. if ($bid) $where['bid'] = $bid;
  715. if ($old_name) $where['old_name'] = $old_name;
  716. if ($domain) $where['domain'] = $domain;
  717. if ($copy_right_date) $where['copy_right_date'] = $copy_right_date;
  718. $page_size = $request->input('page_size', 15);
  719. $res = BookConfigService::getBooks($where, $order, $page_size);
  720. /*$exist = Cache::get('setPromotionStatus', '');
  721. $book_ids = explode(',', $exist);*/
  722. //\Log::info('setPromotionStatus is: ' . $exist);
  723. foreach ($res as &$item) {
  724. $item->book_special_channels = [];
  725. $channels = BookSpecialChannelService::getChannelsByBid($item->bid);
  726. if ($channels) {
  727. $channel_array = [];
  728. foreach ($channels as $channel) {
  729. $channel_array[] = $channel->channel_user_id;
  730. }
  731. $item->book_special_channels = $channel_array;
  732. }
  733. $book_tags = BookTagsService::getBookTags($item->bid);
  734. $item->tags = $book_tags;
  735. $item->is_promotion = $item->is_current_week_promotion;
  736. /*foreach ($book_ids as $book_id) {
  737. if ($book_id == $item->bid) {
  738. $item->is_promotion = 1;
  739. }
  740. }*/
  741. }
  742. return response()->pagination(new BookTransformer, $res);
  743. }
  744. /**
  745. * @apiVersion 1.0.0
  746. * @apiDescription 获取屏蔽图书
  747. * @api {get} cover/books 获取屏蔽图书
  748. * @apiParam {Int} [page_size] 分页大小
  749. * @apiParam {Int} [page] 页码
  750. * @apiParam {String} [domain] 域名 按域名查询
  751. * @apiParam {String} [old_name] 旧书名 按旧书名查询
  752. * @apiParam {String} [copy_right_date] 版权到期时间
  753. * @apiGroup Book
  754. * @apiName getCoverBooks
  755. * @apiSuccess {int} code 状态码
  756. * @apiSuccess {String} msg 信息
  757. * @apiSuccess {object} data 结果集
  758. * @apiSuccess {Array} data 结果数据集
  759. * @apiSuccess {Int} data.book_id bid
  760. * @apiSuccess {String} data.book_name 书名
  761. * @apiSuccess {String} data.book_summary 简介
  762. * @apiSuccess {String} data.book_author 作者
  763. * @apiSuccess {String} data.cover_url 封面
  764. * @apiSuccess {Int} data.book_word_count 字数
  765. * @apiSuccess {Int} data.book_chapter_total 章节数
  766. * @apiSuccess {Int} data.book_category_id 分类
  767. * @apiSuccess {String} data.book_category 分类名
  768. * @apiSuccess {String} data.book_end_status 是否完结
  769. * @apiSuccess {String} data.book_published_time 发布时间
  770. * @apiSuccess {String} data.copyright 版权信息
  771. * @apiSuccess {Int} data.force_subscribe_chapter_id 强制关注的章节数
  772. * @apiSuccess {String} data.update_time 更新时间
  773. * @apiSuccess {Int} data.is_on_shelf 是否上架
  774. * @apiSuccess {String} data.book_price 是否上架
  775. * @apiSuccess {String} data.recommend_index 推荐指数
  776. * @apiSuccess {Int} data.charge_type 收费类型
  777. * @apiSuccess {Int} data.keyword 关键词
  778. * @apiSuccess {Int} data.is_show_index_content 是否显示推荐指数文本
  779. * @apiSuccess {Int} data.click_count 点击数
  780. * @apiSuccess {Int} data.product_id product_id
  781. * @apiSuccess {Int} data.sex_preference 性格偏向
  782. * @apiSuccess {String} data.old_name 旧书名
  783. * @apiSuccess {String} data.is_high_quality 是否优质
  784. * @apiSuccessExample {json} Success-Response:
  785. * HTTP/1.1 200 OK
  786. * {
  787. * code: 0,
  788. * msg: "",
  789. * data: {
  790. * [
  791. * {
  792. * book_id: 5,
  793. * book_name: "肌缘巧合",
  794. * book_summary: "&nbsp;&nbsp;&nbsp;&nbsp;他是权势倾天,纵横商界的王者,却偏偏钟情于她,一宠成瘾。“女人,我要你......只要你能满足我,别墅、游轮、支票,你随便挑。”她羞涩的半低着头:“我只想要你。”他挑眉,“你野心不小啊!”她妩媚一笑,解开他的领带,“难道你不愿意!”他宠她爱她,给她所有想要的。只是有一天她终于忍不住暴走,“靠,你有没有节制呀?我要离婚。”",
  795. * book_author: "妖火",
  796. * cover_url: "http://www.leyuee.com/cover/0/8.jpg",
  797. * book_word_count: 0,
  798. * book_chapter_total: 0,
  799. * book_category_id: null,
  800. * book_category: "爆笑,宠文,潜规则",
  801. * book_end_status: 8,
  802. * book_published_time: null,
  803. * copyright: null,
  804. * charge_type: null,
  805. * force_subscribe_chapter_id: 0,
  806. * update_time: null,
  807. * is_on_shelf: 1,
  808. * book_price: null,
  809. * keyword: "温馨,虐心,清水",
  810. * recommend_index:2,
  811. * is_show_index_content:0,
  812. * click_count:0,
  813. * product_id:0,
  814. * sex_preference:0,
  815. * },
  816. * {}
  817. * ],
  818. * meta:{}
  819. * }
  820. * }
  821. */
  822. public function getCoverBooks(Request $request)
  823. {
  824. $where['is_on_shelf'] = [3, 4];
  825. $key = $request->input('key');
  826. if ($key) $where['key'] = $key;
  827. $author = $request->input('author');
  828. if ($author) $where['author'] = $author;
  829. $category_id = $request->input('category_id');
  830. if ($category_id) {
  831. if ($category_id == 1) {
  832. $where['channel_name'] = '男频';
  833. } elseif ($category_id == 2) {
  834. $where['channel_name'] = '女频';
  835. } else {
  836. $where['category_id'] = $category_id;
  837. }
  838. }
  839. $is_on_shelf = $request->input('is_on_shelf');
  840. if ($is_on_shelf) $where['is_on_shelf'] = $is_on_shelf;
  841. $old_name = $request->input('old_name');
  842. $domain = $request->input('domain');
  843. $copy_right_date = $request->input('copy_right_date');
  844. $bid = $request->input('bid');
  845. if ($bid) $where['bid'] = $bid;
  846. if ($old_name) $where['old_name'] = $old_name;
  847. if ($domain) $where['domain'] = $domain;
  848. if ($copy_right_date) $where['copy_right_date'] = $copy_right_date;
  849. $page_size = $request->input('page_size', 15);
  850. $res = BookConfigService::getBooks($where, [], $page_size);
  851. return response()->pagination(new BookTransformer, $res);
  852. }
  853. /**
  854. * @apiVersion 1.0.0
  855. * @apiDescription 获取优质书籍
  856. * @api {get} getHighQualityBooks/books 获取优质书籍
  857. * @apiParam {Int} [page_size] 分页大小
  858. * @apiParam {Int} [page] 页码
  859. * @apiParam {String} [domain] 域名 按域名查询
  860. * @apiParam {String} [old_name] 旧书名 按旧书名查询
  861. * @apiParam {String} [copy_right_date] 版权到期时间
  862. * @apiGroup Book
  863. * @apiName getHighQualityBooks
  864. * @apiSuccess {int} code 状态码
  865. * @apiSuccess {String} msg 信息
  866. * @apiSuccess {object} data 结果集
  867. * @apiSuccess {Array} data 结果数据集
  868. * @apiSuccess {Int} data.book_id bid
  869. * @apiSuccess {String} data.book_name 书名
  870. * @apiSuccess {String} data.book_summary 简介
  871. * @apiSuccess {String} data.book_author 作者
  872. * @apiSuccess {String} data.cover_url 封面
  873. * @apiSuccess {Int} data.book_word_count 字数
  874. * @apiSuccess {Int} data.book_chapter_total 章节数
  875. * @apiSuccess {Int} data.book_category_id 分类
  876. * @apiSuccess {String} data.book_category 分类名
  877. * @apiSuccess {String} data.book_end_status 是否完结
  878. * @apiSuccess {String} data.book_published_time 发布时间
  879. * @apiSuccess {String} data.copyright 版权信息
  880. * @apiSuccess {Int} data.force_subscribe_chapter_id 强制关注的章节数
  881. * @apiSuccess {String} data.update_time 更新时间
  882. * @apiSuccess {Int} data.is_on_shelf 是否上架
  883. * @apiSuccess {String} data.book_price 是否上架
  884. * @apiSuccess {String} data.recommend_index 推荐指数
  885. * @apiSuccess {Int} data.charge_type 收费类型
  886. * @apiSuccess {Int} data.keyword 关键词
  887. * @apiSuccess {Int} data.is_show_index_content 是否显示推荐指数文本
  888. * @apiSuccess {Int} data.click_count 点击数
  889. * @apiSuccess {Int} data.product_id product_id
  890. * @apiSuccess {Int} data.sex_preference 性格偏向
  891. * @apiSuccess {String} data.old_name 旧书名
  892. * @apiSuccess {String} data.is_high_quality 是否优质
  893. * @apiSuccessExample {json} Success-Response:
  894. * HTTP/1.1 200 OK
  895. * {
  896. * code: 0,
  897. * msg: "",
  898. * data: {
  899. * [
  900. * {
  901. * book_id: 5,
  902. * book_name: "肌缘巧合",
  903. * book_summary: "&nbsp;&nbsp;&nbsp;&nbsp;他是权势倾天,纵横商界的王者,却偏偏钟情于她,一宠成瘾。“女人,我要你......只要你能满足我,别墅、游轮、支票,你随便挑。”她羞涩的半低着头:“我只想要你。”他挑眉,“你野心不小啊!”她妩媚一笑,解开他的领带,“难道你不愿意!”他宠她爱她,给她所有想要的。只是有一天她终于忍不住暴走,“靠,你有没有节制呀?我要离婚。”",
  904. * book_author: "妖火",
  905. * cover_url: "http://www.leyuee.com/cover/0/8.jpg",
  906. * book_word_count: 0,
  907. * book_chapter_total: 0,
  908. * book_category_id: null,
  909. * book_category: "爆笑,宠文,潜规则",
  910. * book_end_status: 8,
  911. * book_published_time: null,
  912. * copyright: null,
  913. * charge_type: null,
  914. * force_subscribe_chapter_id: 0,
  915. * update_time: null,
  916. * is_on_shelf: 1,
  917. * book_price: null,
  918. * keyword: "温馨,虐心,清水",
  919. * recommend_index:2,
  920. * is_show_index_content:0,
  921. * click_count:0,
  922. * product_id:0,
  923. * sex_preference:0,
  924. * },
  925. * {}
  926. * ],
  927. * meta:{}
  928. * }
  929. * }
  930. */
  931. public function getHighQualityBooks(Request $request)
  932. {
  933. $where = ['is_on_shelf' => [1, 2]];
  934. $where = ['is_high_quality' => 1];
  935. $key = $request->input('key');
  936. if ($key) $where['key'] = $key;
  937. $author = $request->input('author');
  938. if ($author) $where['author'] = $author;
  939. $category_id = $request->input('category_id');
  940. if ($category_id) {
  941. if ($category_id == 1) {
  942. $where['channel_name'] = '男频';
  943. } elseif ($category_id == 2) {
  944. $where['channel_name'] = '女频';
  945. } else {
  946. $where['category_id'] = $category_id;
  947. }
  948. }
  949. $old_name = $request->input('old_name');
  950. $domain = $request->input('domain');
  951. $copy_right_date = $request->input('copy_right_date');
  952. $bid = $request->input('bid');
  953. if ($bid) $where['bid'] = $bid;
  954. if ($old_name) $where['old_name'] = $old_name;
  955. if ($domain) $where['domain'] = $domain;
  956. if ($copy_right_date) $where['copy_right_date'] = $copy_right_date;
  957. $page_size = $request->input('page_size', 15);
  958. $res = BookConfigService::getBooks($where, [], $page_size);
  959. return response()->pagination(new BookTransformer, $res);
  960. }
  961. /**
  962. * @apiVersion 1.0.0
  963. * @apiDescription 编辑优选
  964. * @api {get} books/editHighQuality 编辑优选
  965. * @apiName editHighQuality
  966. * @apiParam {Int} bid bid
  967. * @apiParam {Int} is_high_quality 添加优质1,取消0
  968. * @apiGroup Book
  969. * @apiSuccess {Int} code 状态码
  970. * @apiSuccess {String} msg 信息
  971. * @apiSuccess {object} data 结果集
  972. * @apiSuccessExample {json} Success-Response:
  973. * HTTP/1.1 200 OK
  974. * {
  975. * code: 0,
  976. * msg: "",
  977. * data: {}
  978. * }
  979. */
  980. public function editHighQuality(Request $request)
  981. {
  982. $bid = $request->input('bid');
  983. $is_high_quality = (int)$request->input('is_high_quality');
  984. if (!$bid) {
  985. return response()->error('PARAM_EMPTY');
  986. }
  987. if (BookConfigService::editIsHighQuality($bid, $is_high_quality)) {
  988. return response()->success();
  989. }
  990. return response()->error('UNKNOWN_ERROR');
  991. }
  992. /**
  993. * @apiVersion 1.0.0
  994. * @apiDescription 上传封面
  995. * @api {post} books/uploadcover 上传封面
  996. * @apiName uploadCover
  997. * @apiParam {Int} bid bid
  998. * @apiParam {File} photo photo
  999. * @apiGroup Book
  1000. * @apiSuccess {Int} code 状态码
  1001. * @apiSuccess {String} msg 信息
  1002. * @apiSuccess {object} data 结果集
  1003. * @apiSuccessExample {json} Success-Response:
  1004. * HTTP/1.1 200 OK
  1005. * {
  1006. * code: 0,
  1007. * msg: "",
  1008. * data: {}
  1009. * }
  1010. */
  1011. public function uploadCover(Request $request)
  1012. {
  1013. $bid = $request->input('bid');
  1014. if (!$request->hasFile('photo') || !$bid) {
  1015. return response()->error('PARAM_EMPTY');
  1016. }
  1017. $file = $request->file('photo');
  1018. //$extension = $file->getClientOriginalName();
  1019. $extension = $file->extension();
  1020. $file_name = date('YmdHis') . $bid . '.' . $extension;
  1021. $upload_res = $this->ossObject()->uploadFile(env('OSS_BUCKET', 'zhuishuyun'), 'book/cover/' . $file_name, $file->path());
  1022. $imageUrl = str_ireplace('zhuishuyun.oss-cn-hangzhou.aliyuncs.com', 'cdn-novel.iycdm.com', $upload_res['oss-request-url']);
  1023. $imageUrl = str_ireplace('http://', 'https://', $imageUrl);
  1024. $imageUrl = $imageUrl . '?x-oss-process=image/resize,w_200/format,jpg';
  1025. $data = ['cover' => $imageUrl];
  1026. if (BookConfigService::updateBookConfig($bid, $data)) {
  1027. return response()->success();
  1028. }
  1029. return response()->error('UNKNOWN_ERROR');
  1030. }
  1031. /**
  1032. * @apiVersion 1.0.0
  1033. * @apiDescription 修改图书描述
  1034. * @api {post} books/updateIntro 修改图书描述
  1035. * @apiName updateIntro
  1036. * @apiParam {Int} bid bid
  1037. * @apiParam {String} intro 内容
  1038. * @apiGroup Book
  1039. * @apiSuccess {Int} code 状态码
  1040. * @apiSuccess {String} msg 信息
  1041. * @apiSuccess {object} data 结果集
  1042. * @apiSuccessExample {json} Success-Response:
  1043. * HTTP/1.1 200 OK
  1044. * {
  1045. * code: 0,
  1046. * msg: "",
  1047. * data: {}
  1048. * }
  1049. */
  1050. public function updateIntro(Request $request)
  1051. {
  1052. $bid = $request->input('bid');
  1053. $intro = $request->input('intro');
  1054. if (!$intro || !$bid) {
  1055. return response()->error('PARAM_EMPTY');
  1056. }
  1057. $res = BookService::updateIntro($bid, $intro);
  1058. if ($res) {
  1059. return response()->success();
  1060. }
  1061. return response()->error('UNKNOWN_ERROR');
  1062. }
  1063. /**
  1064. * @apiVersion 1.0.0
  1065. * @apiDescription 修改推荐文案
  1066. * @api {post} books/editRecommendChapterPositionWords 修改推荐文案
  1067. * @apiName editRecommendChapterPositionWords
  1068. * @apiParam {String} content 内容
  1069. * @apiGroup Book
  1070. * @apiSuccess {Int} code 状态码
  1071. * @apiSuccess {String} msg 信息
  1072. * @apiSuccess {object} data 结果集
  1073. * @apiSuccessExample {json} Success-Response:
  1074. * HTTP/1.1 200 OK
  1075. * {
  1076. * code: 0,
  1077. * msg: "",
  1078. * data: {}
  1079. * }
  1080. */
  1081. public function editRecommendChapterPositionWords(Request $request)
  1082. {
  1083. $content = $request->input('content');
  1084. if (!$content) {
  1085. return response()->error('PARAM_EMPTY');
  1086. }
  1087. Storage::put('RecommendChapterPositionWord.txt', $content);
  1088. return response()->success();
  1089. }
  1090. /**
  1091. * @apiVersion 1.0.0
  1092. * @apiDescription 修改推荐章节
  1093. * @api {get} books/editRecommendcid 修改推荐章节
  1094. * @apiName editRecommendcid
  1095. * @apiParam {Int} bid bid
  1096. * @apiParam {Int} cid cid
  1097. * @apiGroup Book
  1098. * @apiSuccess {Int} code 状态码
  1099. * @apiSuccess {String} msg 信息
  1100. * @apiSuccess {object} data 结果集
  1101. * @apiSuccessExample {json} Success-Response:
  1102. * HTTP/1.1 200 OK
  1103. * {
  1104. * code: 0,
  1105. * msg: "",
  1106. * data: {}
  1107. * }
  1108. */
  1109. public function editRecommendcid(Request $request)
  1110. {
  1111. $bid = $request->input('bid');
  1112. $cid = $request->input('cid');
  1113. if (!$bid || !$cid) {
  1114. return response()->error('PARAM_EMPTY');
  1115. }
  1116. if (BookConfigService::editRecommendCid($bid, $cid)) {
  1117. return response()->success();
  1118. } else {
  1119. return response()->error('UNKNOWN_ERROR');
  1120. }
  1121. }
  1122. private function ossObject()
  1123. {
  1124. $accessKeyId = env('OSS_ACCESS_ID');
  1125. $accessKeySecret = env('OSS_ACCESS_KEY');
  1126. $endpoint = env('OSS_END_POINT');
  1127. $ossClient = null;
  1128. try {
  1129. $ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint);
  1130. } catch (OssException $e) {
  1131. return null;
  1132. }
  1133. return $ossClient;
  1134. }
  1135. /**
  1136. * @apiVersion 1.0.0
  1137. * @apiDescription 获取推荐文案
  1138. * @api {get} books/getRecommendChapterPositionWords 获取推荐文案
  1139. * @apiName getRecommendChapterPositionWords
  1140. * @apiGroup Book
  1141. * @apiSuccess {Int} code 状态码
  1142. * @apiSuccess {String} msg 信息
  1143. * @apiSuccess {object} data 结果集
  1144. * @apiSuccessExample {json} Success-Response:
  1145. * HTTP/1.1 200 OK
  1146. * {
  1147. * code: 0,
  1148. * msg: "",
  1149. * data: {
  1150. * content:建议此章节生成推广文案(原文转化率好)
  1151. * }
  1152. * }
  1153. */
  1154. public function getRecommendChapterPositionWords(Request $request)
  1155. {
  1156. $content = '';
  1157. if (Storage::exists('RecommendChapterPositionWord.txt')) {
  1158. $content = Storage::get('RecommendChapterPositionWord.txt');
  1159. } else {
  1160. $content = '建议此章节生成推广文案(原文转化率好)';
  1161. }
  1162. return response()->success(['content' => $content]);
  1163. }
  1164. /**
  1165. * @apiVersion 1.0.0
  1166. * @apiDescription 书籍设置渠道标识功能
  1167. * @api {post} books/setChannelSpecialBook 获取推荐文案
  1168. * @apiName setChannelSpecialBook
  1169. * @apiParam {Int} bid 书本id
  1170. * @apiParam {Int} channel_id 渠道id
  1171. * @apiGroup Book
  1172. * @apiSuccess {Int} code 状态码
  1173. * @apiSuccess {String}msg 信息
  1174. * @apiSuccess {object}data 结果集
  1175. * @apiSuccessExample {json} Success-Response:
  1176. * HTTP/1.1 200 OK
  1177. * {
  1178. * code: 0,
  1179. * msg: "",
  1180. * data: {}
  1181. * }
  1182. */
  1183. public function setChannelSpecialBook(Request $request)
  1184. {
  1185. $bid = $request->has('bid') ? $request->input('bid') : '';
  1186. $channel_user_id = $request->has('channel_user_id') ? $request->input('channel_user_id') : '';
  1187. if (empty($bid)) {
  1188. return response()->error("PARAM_EMPTY");
  1189. } else {
  1190. if (empty($channel_user_id)) {
  1191. $data = BookSpecialChannelService::clearSpecialChannle($bid);
  1192. } else {
  1193. $channel_user_ids = explode(',', $channel_user_id);
  1194. $channels = array_filter($channel_user_ids);
  1195. $data = BookSpecialChannelService::addSpecialChannle($bid, $channels);
  1196. }
  1197. if ($data) {
  1198. return response()->success();
  1199. }
  1200. return response()->error("HANDLE_FAILED");
  1201. }
  1202. }
  1203. public function copyBook(Request $request)
  1204. {
  1205. //return 1111;
  1206. $bid = $request->has('bid') ? $request->input('bid') : '';
  1207. if (empty($bid)) {
  1208. return response()->error("PARAM_EMPTY");
  1209. }
  1210. $book_info = Book::find($bid);
  1211. if (!$book_info) {
  1212. return response()->error("PARAM_EMPTY");
  1213. }
  1214. $book_config_info = BookConfig::where('bid', $bid)->first();
  1215. if (!$book_config_info) {
  1216. return response()->error("PARAM_EMPTY");
  1217. }
  1218. $book = Book::create([
  1219. 'ly_bid' => $book_info->ly_bid,
  1220. 'name' => $book_info->name,
  1221. 'author' => $book_info->author,
  1222. 'intro' => $book_info->intro,
  1223. 'cover' => $book_info->cover,
  1224. 'keyword' => $book_info->keyword,
  1225. 'category_id' => $book_info->category_id,
  1226. 'status' => $book_info->status,
  1227. 'chapter_count' => $book_info->chapter_count,
  1228. 'first_cid' => 0,
  1229. 'last_cid' => 0,
  1230. 'last_chapter' => $book_info->last_chapter,
  1231. 'size' => $book_info->size,
  1232. 'category_name' => $book_info->category_name,
  1233. ]);
  1234. $product = ProductService::addProduct(['price' => 8.99, 'type' => 'BOOK_ORDER', 'given' => 0, 'is_default' => 0, 'is_enabled' => 0]);
  1235. DB::table('book_configs')->insert([
  1236. 'bid' => $book->id,
  1237. 'force_subscribe_chapter_seq' => $book_config_info->force_subscribe_chapter_seq,
  1238. 'book_name' => $book_config_info->book_name . '-复制',
  1239. 'price' => '8.99',
  1240. 'cover' => $book_config_info->cover,
  1241. 'charge_type' => $book_config_info->charge_type,
  1242. 'is_on_shelf' => 0,
  1243. 'product_id' => $product->id,
  1244. 'cp_source' => $book_config_info->cp_source,
  1245. 'vip_seq' => $book_config_info->vip_seq,
  1246. 'hot' => $book_config_info->hot,
  1247. 'promotion_domain' => $book_config_info->promotion_domain,
  1248. 'recommend_cid' => $book_config_info->recommend_cid,
  1249. 'is_high_quality' => $book_config_info->is_high_quality,
  1250. 'source_domain' => $book_config_info->source_domain,
  1251. 'is_show_index_content' => $book_config_info->is_show_index_content,
  1252. 'created_at' => date('Y-m-d H:i:s'),
  1253. 'updated_at' => date('Y-m-d H:i:s')
  1254. ]);
  1255. $sql = 'CALL copybook(' . $bid . ',' . $book->id . ')';
  1256. DB::select($sql);
  1257. $this->adjustSequentOne($book->id);
  1258. return response()->success(['bid' => $book->id]);
  1259. }
  1260. public function adjustSequentOne($bid)
  1261. {
  1262. $chapter_list = DB::table('chapters')->orderBy('sequence')->where('bid', $bid)->select('id')->get();
  1263. $prev = 0;
  1264. $i = 0;
  1265. $first = '';
  1266. $last = '';
  1267. foreach ($chapter_list as $chapter) {
  1268. if ($i == 0) {
  1269. $first = $chapter;
  1270. }
  1271. if ($prev) {
  1272. DB::table('chapters')->where('id', $chapter->id)->update(['prev_cid' => $prev]);
  1273. DB::table('chapters')->where('id', $prev)->update(['next_cid' => $chapter->id]);
  1274. }
  1275. $prev = $chapter->id;
  1276. $i++;
  1277. $last = $chapter;
  1278. }
  1279. Book::where('id', $bid)->update(['first_cid' => $first->id, 'last_cid' => $last->id]);
  1280. }
  1281. public function getAllBookSimple(Request $request)
  1282. {
  1283. $is_on_shelf = $request->input('is_on_shelf');
  1284. $order = $request->input('order');
  1285. $seq = $request->input('sequence', 'desc');
  1286. if ($is_on_shelf) {
  1287. $is_on_shelf = explode(',', $is_on_shelf);
  1288. } else {
  1289. $is_on_shelf = [1, 2];
  1290. }
  1291. $order_arr = [];
  1292. if ($order) {
  1293. $order_arr[0] = $order;
  1294. $order_arr[1] = 'desc';
  1295. if ($seq && $seq == 'asc') {
  1296. $order_arr[1] = 'asc';
  1297. }
  1298. }
  1299. // 增加加密的bid字段
  1300. $books = BookConfig::getAllBooks($is_on_shelf, $order_arr);
  1301. foreach ($books as $key => $book) {
  1302. $books[$key]['bid_hash'] = Hashids::encode($books[$key]['bid']);
  1303. }
  1304. return response()->success($books);
  1305. }
  1306. /**
  1307. * @apiVersion 1.0.0
  1308. * @apiDescription 设置章节价格
  1309. * @api {get} books/setChapterPrice 设置章节价格
  1310. * @apiName setChapterPrice
  1311. * @apiParam {Int} type 类型(1,2) 1代表 单个渠道,2代表渠道下所有的site
  1312. * @apiParam {Int} channel_id 渠道id
  1313. * @apiParam {float} price 价格 (千字/毛)
  1314. * @apiGroup Book
  1315. * @apiSuccess {Int} code 状态码
  1316. * @apiSuccess {String}msg 信息
  1317. * @apiSuccess {object}data 结果集
  1318. * @apiSuccessExample {json} Success-Response:
  1319. * HTTP/1.1 200 OK
  1320. * {
  1321. * code: 0,
  1322. * msg: "",
  1323. * data: {}
  1324. * }
  1325. */
  1326. public function setChapterPrice(Request $request)
  1327. {
  1328. $type = $request->input('type', 1);
  1329. $channel_id = $request->input('channel_id');
  1330. $price = $request->input('price');
  1331. if (!$channel_id || !$price) {
  1332. return response()->error("PARAM_EMPTY");
  1333. }
  1334. if (!is_numeric($price)) {
  1335. return response()->error("PARAM_EMPTY");
  1336. }
  1337. //distribution_channel_id
  1338. if ($type == 1) {
  1339. BookService::setChapterPrice($channel_id, $price);
  1340. }
  1341. //channel_user_id
  1342. if ($type == 2) {
  1343. $res = ChannelService::getByChannelUserId($channel_id);
  1344. foreach ($res as $v) {
  1345. BookService::setChapterPrice($v->id, $price);
  1346. }
  1347. }
  1348. return response()->success();
  1349. }
  1350. /**
  1351. * @apiVersion 1.0.0
  1352. * @apiDescription 根据书名获取图书
  1353. * @api {get} books/getSimpleBookListByName 根据书名获取图书
  1354. * @apiName getSimpleBookListByName
  1355. * @apiParam {String} book_name 书名
  1356. * @apiGroup Book
  1357. * @apiSuccess {Int} code 状态码
  1358. * @apiSuccess {String}msg 信息
  1359. * @apiSuccess {object}data 结果集
  1360. * @apiSuccess {int} data.bid bid
  1361. * @apiSuccess {string} data.book_name 书名
  1362. * @apiSuccessExample {json} Success-Response:
  1363. * HTTP/1.1 200 OK
  1364. * {
  1365. * code: 0,
  1366. * msg: "",
  1367. * data: {}
  1368. * }
  1369. */
  1370. public function getSimpleBookListByName(Request $request)
  1371. {
  1372. $name = $request->input('book_name');
  1373. if (empty($name)) {
  1374. return response()->success();
  1375. }
  1376. $res = BookConfigService::getBooksByName(trim($name));
  1377. return response()->success($res);
  1378. }
  1379. /**
  1380. * @apiVersion 1.0.0
  1381. * @apiDescription 设置分校推荐榜
  1382. * @api {post} books/setEditorRecommendBooks 设置分校推荐榜
  1383. * @apiName setEditorRecommendBooks
  1384. * @apiParam {String} important_bids 重点bid列表,逗号隔开(1,2,3)
  1385. * @apiParam {String} unimportant_bids 非重点bid列表(112,232,312)
  1386. * @apiGroup Book
  1387. * @apiSuccess {Int} code 状态码
  1388. * @apiSuccess {String} msg 信息
  1389. * @apiSuccess {object} ata 结果集
  1390. * @apiSuccessExample {json} Success-Response:
  1391. * HTTP/1.1 200 OK
  1392. * {
  1393. * code: 0,
  1394. * msg: "",
  1395. * data: {}
  1396. * }
  1397. */
  1398. public function setEditorRecommendBooks(Request $request)
  1399. {
  1400. //$type = $request->input('type');
  1401. $important_bids = $request->input('important_bids');
  1402. $unimportant_bids = $request->input('unimportant_bids');
  1403. if (empty($important_bids) || empty($unimportant_bids)) {
  1404. return response()->error("PARAM_EMPTY");
  1405. }
  1406. Redis::hincrby('channel_recomm_books', 'count', 1);
  1407. Redis::hset('channel_recomm_books', 'important', $important_bids);
  1408. Redis::hset('channel_recomm_books', 'unimportant', $unimportant_bids);
  1409. $nowcount = Redis::hget('channel_recomm_books', 'count');
  1410. if (!$nowcount) $nowcount = 0;
  1411. $old_import = BookConfigService::getSimpleBooksByIds(explode(',', $important_bids));
  1412. $data = [];
  1413. foreach ($old_import as $v) {
  1414. $data[] = ['bid' => $v->bid, 'book_name' => $v->book_name, 'type' => 'IMPORTANT',
  1415. 'count' => $nowcount, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')];
  1416. }
  1417. $old_unimportant = BookConfigService::getSimpleBooksByIds(explode(',', $unimportant_bids));
  1418. foreach ($old_unimportant as $val) {
  1419. $data[] = ['bid' => $val->bid, 'book_name' => $val->book_name, 'type' => 'UNIMPORTANT',
  1420. 'count' => $nowcount, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')];
  1421. }
  1422. if ($data) {
  1423. DB::table('channel_editor_recommend_rank')->insert($data);
  1424. }
  1425. return response()->success();
  1426. }
  1427. /**
  1428. * @apiVersion 1.0.0
  1429. * @apiDescription 获取分校推荐榜
  1430. * @api {get} books/getEditorRecommendBooks 获取分校推荐榜
  1431. * @apiName getEditorRecommendBooks
  1432. * @apiParam {String} [count] 次数默认最近一次
  1433. * @apiGroup Book
  1434. * @apiSuccess {Int} code 状态码
  1435. * @apiSuccess {String} msg 信息
  1436. * @apiSuccess {object} data 结果集
  1437. * @apiSuccess {int} data.total_count 总次数
  1438. * @apiSuccess {int} data.now 当前次数
  1439. * @apiSuccess {object} data.important 重点渠道
  1440. * @apiSuccess {int} data.important.bid bid
  1441. * @apiSuccess {string} data.important.book_name 书名
  1442. * @apiSuccess {object} data.unimportant
  1443. * @apiSuccessExample {json} Success-Response:
  1444. * HTTP/1.1 200 OK
  1445. * {
  1446. * code: 0,
  1447. * msg: "",
  1448. * data: {
  1449. * total_count:3,
  1450. * now :3
  1451. * important:[]
  1452. * unimportant
  1453. * }
  1454. * }
  1455. */
  1456. public function getEditorRecommendBooks(Request $request)
  1457. {
  1458. $type = $request->input('count', 0);
  1459. $nowcount = Redis::hget('channel_recomm_books', 'count');
  1460. if (!$type) $type = $nowcount;
  1461. $important_books = null;
  1462. $unimportant_books = null;
  1463. if ($type) {
  1464. $important_books = DB::table('channel_editor_recommend_rank')->where('count', $type)->where('type', 'IMPORTANT')->select('bid', 'book_name')->get();
  1465. $unimportant_books = DB::table('channel_editor_recommend_rank')->where('count', $type)->where('type', 'UNIMPORTANT')->select('bid', 'book_name')->get();
  1466. } else {
  1467. $important = Redis::hget('channel_recomm_books', 'important');
  1468. if ($important) {
  1469. $important_bid = explode(',', $important);
  1470. $important_books = BookConfigService::getSimpleBooksByIds($important_bid);
  1471. }
  1472. $unimportant = Redis::hget('channel_recomm_books', 'unimportant');
  1473. if ($unimportant) {
  1474. $unimportant_bid = explode(',', $unimportant);
  1475. $unimportant_books = BookConfigService::getSimpleBooksByIds($unimportant_bid);
  1476. }
  1477. }
  1478. $res = ['total_count' => $nowcount, 'now' => $type, 'important' => $important_books, 'unimportant' => $unimportant_books];
  1479. return response()->success($res);
  1480. }
  1481. public function getBookIntro(Request $request)
  1482. {
  1483. $bid = (int)$request->get('bid', 0);
  1484. $book_name = $request->get('book_name', '');
  1485. if (empty($bid) && empty($book_name)) {
  1486. return response()->error("PARAM_EMPTY");
  1487. }
  1488. $info = BookConfigService::getBookIntroByBid($bid, $book_name);
  1489. if (empty($info)) {
  1490. $info = [
  1491. ['book_name' => $book_name.'(0)', 'intro' => '']
  1492. ];
  1493. }
  1494. return response()->success($info);
  1495. }
  1496. public function getBookCommentStats(Request $request){
  1497. /*$bid = $request->input('bid');
  1498. if(!$bid){
  1499. return response()->error('PARAM_ERROR');
  1500. }*/
  1501. }
  1502. /**
  1503. * 测书更新
  1504. * @param Request $request
  1505. */
  1506. public function updateTestBook(Request $request)
  1507. {
  1508. $bid = (int)$request->get('bid', 0);
  1509. if (empty($bid)) {
  1510. return response()->error("PARAM_EMPTY");
  1511. }
  1512. $status = $request->get('status');
  1513. if (empty($status)) {
  1514. return response()->error("PARAM_EMPTY");
  1515. }
  1516. $plan_push_user_num = $request->get('plan_push_user_num');
  1517. if (empty($plan_push_user_num)) {
  1518. return response()->error("PARAM_EMPTY");
  1519. }
  1520. // 检测书库是否存在这本书
  1521. $is_one_shelfs = [1,2];
  1522. $origin_book = BookConfigService::getBookByIdAndStatus($bid,$is_one_shelfs);
  1523. if(empty($origin_book)){
  1524. return response()->error("BOOK_NOT_EXIST");
  1525. }
  1526. // 如果已经存在测书,则更新状态, 不存在则要检测测书数量
  1527. if($origin_book->test_status == 0){
  1528. // 检测书库是否已经达到目标数量的测试书
  1529. $test_books = BookConfigService::get_test_books(1);
  1530. if(count($test_books) >= 50){
  1531. return response()->error("TEST_BOOK_LIMIT_NUM");
  1532. }
  1533. }
  1534. // 开启测试书
  1535. BookConfigService::updateTestBook($bid, $status,$plan_push_user_num);
  1536. return response()->success();
  1537. }
  1538. /**
  1539. * 测书统计数据
  1540. * @param Request $request
  1541. */
  1542. public function getTestBookStatistics(Request $request)
  1543. {
  1544. // 获取测试的书籍列表
  1545. $test_books = BookConfigService::get_all_test_books(false);
  1546. $test_books = BookService::getBookStatistics($test_books);
  1547. return response()->pagination(new SmartPushBookTransformer, $test_books);
  1548. }
  1549. /**
  1550. * 智能推送统计数据
  1551. * @param Request $request
  1552. */
  1553. public function getSmartPushBookStatistics(Request $request)
  1554. {
  1555. // 获取测试的书籍列表
  1556. $smart_push_books = BookConfigService::get_all_smart_push_books(false);
  1557. $smart_push_books = BookService::getBookStatistics($smart_push_books);
  1558. return response()->pagination(new SmartPushBookTransformer, $smart_push_books);
  1559. }
  1560. /**
  1561. * 导出测书统计数据
  1562. * @param Request $request
  1563. */
  1564. public function exportGetTestBookStatistics(Request $request)
  1565. {
  1566. // 获取书籍列表
  1567. $books = BookConfigService::get_all_test_books(true);
  1568. $book_statistics = BookService::getBookStatistics($books);
  1569. self::exportBookStatistics($book_statistics,'测书统计');
  1570. }
  1571. /**
  1572. * 导出智能推送统计数据
  1573. * @param Request $request
  1574. */
  1575. public function exportGetSmartPushBookStatistics(Request $request)
  1576. {
  1577. // 获取书籍列表
  1578. $books = BookConfigService::get_all_smart_push_books(true);
  1579. $book_statistics = BookService::getBookStatistics($books);
  1580. self::exportBookStatistics($book_statistics,'智能推送统计');
  1581. }
  1582. function exportBookStatistics($book_statistics,$csv_name){
  1583. header("Content-type:application/vnd.ms-excel");
  1584. header("Content-Disposition:attachment;filename=" . $csv_name . date("YmdHis") . ".csv");
  1585. echo iconv("UTF-8", "GBK", "\"书名\",\"bid\",\"创建时间\",\"计划曝光量\",\"真实曝光量\",\"访问uv\",\"第二章uv\",\"订阅人数\",\"订阅金额\",\"充值人数\",\"充值金额\",\"状态\"\r\n");
  1586. foreach ($book_statistics as $item) {
  1587. echo("\"" . mb_convert_encoding($item->book_name, "GBK", "UTF-8") . "\",");
  1588. echo("\"" . mb_convert_encoding($item->bid, "GBK", "UTF-8") . "\",");
  1589. echo("\"" . mb_convert_encoding(isset($item->test_update_time) ? date('Y-m-d H:i:s',strtotime($item->test_update_time)):'', "GBK", "UTF-8") . "\",");
  1590. echo("\"" . mb_convert_encoding($item->plan_push_user_num, "GBK", "UTF-8") . "\",");
  1591. echo("\"" . mb_convert_encoding($item->real_push_user_num, "GBK", "UTF-8") . "\",");
  1592. echo("\"" . mb_convert_encoding($item->uv, "GBK", "UTF-8") . "\",");
  1593. echo("\"" . mb_convert_encoding($item->second_chapter_uv, "GBK", "UTF-8") . "\",");
  1594. echo("\"" . mb_convert_encoding($item->book_user_num, "GBK", "UTF-8") . "\",");
  1595. echo("\"" . mb_convert_encoding(round($item->book_amount/100,2), "GBK", "UTF-8") . "\",");
  1596. echo("\"" . mb_convert_encoding($item->charge_user_num, "GBK", "UTF-8") . "\",");
  1597. echo("\"" . mb_convert_encoding(round($item->charge_amount/100,2), "GBK", "UTF-8") . "\",");
  1598. if($item->test_status == 1){
  1599. echo("\"" . mb_convert_encoding("测书中", "GBK", "UTF-8") . "\"\r\n");
  1600. }else{
  1601. echo("\"" . mb_convert_encoding("已暂停", "GBK", "UTF-8") . "\"\r\n");
  1602. }
  1603. }
  1604. exit();
  1605. }
  1606. /**
  1607. * @param Request $request
  1608. * @return mixed
  1609. */
  1610. public function editorRecommendMsg(Request $request) {
  1611. $msg = trim($request->input('recommend_msg',''));
  1612. $bid = $request->input('bid','');
  1613. if(empty($msg) || empty($bid)) {
  1614. return response()->error('PARAM_EMPTY');
  1615. }
  1616. $res = BookConfig::where('bid',$bid)->update(['editor_recommend'=>$msg]);
  1617. return response()->success($res);
  1618. }
  1619. public function getEditorRecommendMsg(Request $request) {
  1620. $bid = $request->input('bid','');
  1621. if(empty($bid)) {
  1622. return response()->error('PARAM_EMPTY');
  1623. }
  1624. $msg = BookConfig::where('bid',$bid)
  1625. ->select('editor_recommend')
  1626. ->first();
  1627. $msg = $msg?$msg->editor_recommend:'';
  1628. return response()->success($msg);
  1629. }
  1630. }