ArticleController.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace App\Http\Controllers\Api\v1;
  3. use App\Http\Controllers\Api\webApp;
  4. use App\Services\Api\ArticleService;
  5. use App\Services\ConfigService;
  6. /**
  7. * 司文章管理
  8. * Class ArticleController
  9. * @package App\Http\Controllers\Api
  10. */
  11. class ArticleController extends webApp
  12. {
  13. /**
  14. * 列表
  15. * @return array
  16. */
  17. public function index()
  18. {
  19. $params =request()->post();
  20. $pageSize = request()->post('pageSize', 15);
  21. $datas = ArticleService::make()->getDataList($params, $pageSize);
  22. return message(1010, true, $datas);
  23. }
  24. /**
  25. * 详情
  26. */
  27. public function info()
  28. {
  29. $params = request()->all();
  30. $id = isset($params['id'])? intval($params['id']) : 0;
  31. if(empty($id)){
  32. return message(1036, false);
  33. }
  34. if($info = ArticleService::make()->getInfo($id)){
  35. return message(1010, true, $info);
  36. }else{
  37. return message(1009, false);
  38. }
  39. }
  40. /**
  41. * 客服推荐数据
  42. */
  43. public function customRecommend()
  44. {
  45. $keywords = ConfigService::make()->getConfigByCode('custom_keywords');
  46. $keywords = $keywords? explode('、',$keywords) : ['问题','常见问题','账号','账号登录','登录','密码','商家','商家合作','物流','发货'];
  47. $datas = [
  48. 'keywords'=> array_filter($keywords),
  49. 'site_custom_phone'=> ConfigService::make()->getConfigByCode('site_custom_phone'),
  50. 'category'=> [
  51. ['id'=>9,'name'=>'常见问题','status'=>1],
  52. ['id'=>10,'name'=>'账号登录','status'=>1],
  53. ['id'=>11,'name'=>'商家合作','status'=>1],
  54. ],
  55. 'recommend'=> ArticleService::make()->getCustomRecommend(),
  56. ];
  57. return message(1010, true, $datas);
  58. }
  59. /**
  60. * 客服咨询数据
  61. */
  62. public function custom()
  63. {
  64. $type = request()->post('type',0);
  65. $keyword = request()->post('keyword','');
  66. $num = request()->post('num',6);
  67. $datas = ArticleService::make()->getCustomRecommend($type, $num, $keyword, $type==0?true:false);
  68. if($datas){
  69. return message(1010, true, $datas);
  70. }else{
  71. return message(1009, false);
  72. }
  73. }
  74. /**
  75. * 单页数据
  76. */
  77. public function page()
  78. {
  79. $params = request()->all();
  80. $type = isset($params['type'])? intval($params['type']) : 0;
  81. if(empty($type)){
  82. return message(1031, false);
  83. }
  84. if($info = ArticleService::make()->getInfoByType($type)){
  85. return message(1010, true, $info);
  86. }else{
  87. return message(1009, false);
  88. }
  89. }
  90. }