View.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2021 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: https://thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // | 免费声明 ( https://thinkadmin.top/disclaimer )
  11. // +----------------------------------------------------------------------
  12. // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
  13. // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
  14. // +----------------------------------------------------------------------
  15. namespace app\wechat\controller\api;
  16. use app\wechat\service\MediaService;
  17. use think\admin\Controller;
  18. /**
  19. * 微信图文显示
  20. * Class View
  21. * @package app\wechat\controller\api
  22. */
  23. class View extends Controller
  24. {
  25. /**
  26. * 图文列表展示
  27. * @param string|integer $id 图文ID编号
  28. * @throws \think\db\exception\DataNotFoundException
  29. * @throws \think\db\exception\DbException
  30. * @throws \think\db\exception\ModelNotFoundException
  31. */
  32. public function news($id = 0)
  33. {
  34. $this->id = $id ?: input('id', 0);
  35. $this->news = MediaService::instance()->news($this->id);
  36. $this->fetch();
  37. }
  38. /**
  39. * 文章内容展示
  40. * @param string|integer $id 文章ID编号
  41. * @throws \think\db\exception\DataNotFoundException
  42. * @throws \think\db\exception\DbException
  43. * @throws \think\db\exception\ModelNotFoundException
  44. */
  45. public function item($id = 0)
  46. {
  47. $map = ['id' => $id ?: input('id', 0)];
  48. $this->app->db->name('WechatNewsArticle')->where($map)->update([
  49. 'read_num' => $this->app->db->raw('read_num+1'),
  50. ]);
  51. $this->info = $this->app->db->name('WechatNewsArticle')->where($map)->find();
  52. $this->fetch();
  53. }
  54. /**
  55. * 文本展示
  56. */
  57. public function text()
  58. {
  59. $this->content = strip_tags(input('content', ''), '<a><img>');
  60. $this->fetch();
  61. }
  62. /**
  63. * 图片展示
  64. */
  65. public function image()
  66. {
  67. $this->content = strip_tags(input('content', ''), '<a><img>');
  68. $this->fetch();
  69. }
  70. /**
  71. * 视频展示
  72. */
  73. public function video()
  74. {
  75. $this->url = strip_tags(input('url', ''), '<a><img>');
  76. $this->title = strip_tags(input('title', ''), '<a><img>');
  77. $this->fetch();
  78. }
  79. /**
  80. * 语音展示
  81. */
  82. public function voice()
  83. {
  84. $this->url = strip_tags(input('url', ''), '<a><img>');
  85. $this->fetch();
  86. }
  87. /**
  88. * 音乐展示
  89. */
  90. public function music()
  91. {
  92. $this->url = strip_tags(input('url', ''), '<a><img>');
  93. $this->desc = strip_tags(input('desc', ''), '<a><img>');
  94. $this->title = strip_tags(input('title', ''), '<a><img>');
  95. $this->fetch();
  96. }
  97. }