PlatformArticle.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. class PlatformArticle extends Api
  6. {
  7. protected $noNeedLogin = '*';
  8. protected $noNeedRight = '*';
  9. protected $model = null;
  10. public function _initialize()
  11. {
  12. parent::_initialize();
  13. $this->model = Db::name('platform_article');
  14. }
  15. /**
  16. * 分类列表
  17. * @return void
  18. */
  19. public function getTypeList()
  20. {
  21. try {
  22. $field = 'id,title';
  23. $where['status'] = 1;
  24. $result = Db::name('platform_article_type')->field($field)->where($where)->order('weigh asc')->select();
  25. $this->success('获取成功',$result);
  26. } catch (Exception $e) {
  27. $this->error($e->getMessage());
  28. }
  29. }
  30. /**
  31. * 资讯列表
  32. * @return void
  33. */
  34. public function getList()
  35. {
  36. try {
  37. $typeId = $this->request->param('type_id',0);
  38. $field = 'id,title,desc,images,video,createtime';
  39. $where['status'] = 1;
  40. $where['type_id'] = $typeId;
  41. $result = Db::name('platform_article')->field($field)
  42. ->where($where)->order('createtime desc')->autopage()->select();
  43. $userName = config('site.article_name') ? config('site.article_name') : '';
  44. $avatar = config('site.article_avatar') ? cdnurl(config('site.article_avatar')) : '';
  45. if (!empty($result)) {
  46. foreach ($result as $key => &$value) {
  47. $value['handeltime'] = weixinDate($value['createtime']);
  48. $value['createtime'] = !empty($value['createtime']) ? date('Y-m-d H:i',$value['createtime']) : '';
  49. $value['avatar'] = $avatar;
  50. $value['name'] = $userName;
  51. }
  52. $result = list_domain_image($result,['images','video']);
  53. }
  54. $this->success('获取成功',$result);
  55. } catch (Exception $e) {
  56. $this->error($e->getMessage());
  57. }
  58. }
  59. /**
  60. * 资讯详情
  61. * @return void
  62. */
  63. public function getInfo()
  64. {
  65. try {
  66. $id = $this->request->param('id',0);
  67. $field = 'id,title,desc,images,video,content,createtime';
  68. $where['status'] = 1;
  69. $where['id'] = $id;
  70. $result = Db::name('platform_article')->field($field)->where($where)->find();
  71. $userName = config('site.article_name') ? config('site.article_name') : '';
  72. $avatar = config('site.article_avatar') ? cdnurl(config('site.article_avatar')) : '';
  73. if (!empty($result)) {
  74. $result['handeltime'] = weixinDate($result['createtime']);
  75. $result['createtime'] = !empty($result['createtime']) ? date('Y.m.d H:i',$result['createtime']) : '';
  76. $result['avatar'] = $avatar;
  77. $result['name'] = $userName;
  78. $result = info_domain_image($result,['images','video']);
  79. }
  80. $this->success('获取成功',$result);
  81. } catch (Exception $e) {
  82. $this->error($e->getMessage());
  83. }
  84. }
  85. }