View.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace app\wechat\controller\api;
  3. use app\wechat\service\MediaService;
  4. use think\admin\Controller;
  5. /**
  6. * 微信图文显示
  7. * Class View
  8. * @package app\wechat\controller\api
  9. */
  10. class View extends Controller
  11. {
  12. /**
  13. * 图文列表展示
  14. * @param string|integer $id 图文ID编号
  15. * @throws \think\db\exception\DataNotFoundException
  16. * @throws \think\db\exception\DbException
  17. * @throws \think\db\exception\ModelNotFoundException
  18. */
  19. public function news($id = 0)
  20. {
  21. $this->id = $id ?: input('id', 0);
  22. $this->news = MediaService::instance()->news($this->id);
  23. $this->fetch();
  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 item($id = 0)
  33. {
  34. $map = ['id' => $id ?: input('id', 0)];
  35. $this->app->db->name('WechatNewsArticle')->where($map)->update([
  36. 'read_num' => $this->app->db->raw('read_num+1'),
  37. ]);
  38. $this->info = $this->app->db->name('WechatNewsArticle')->where($map)->find();
  39. $this->fetch();
  40. }
  41. /**
  42. * 文本展示
  43. */
  44. public function text()
  45. {
  46. $this->content = strip_tags(input('content', ''), '<a><img>');
  47. $this->fetch();
  48. }
  49. /**
  50. * 图片展示
  51. */
  52. public function image()
  53. {
  54. $this->content = strip_tags(input('content', ''), '<a><img>');
  55. $this->fetch();
  56. }
  57. /**
  58. * 视频展示
  59. */
  60. public function video()
  61. {
  62. $this->url = strip_tags(input('url', ''), '<a><img>');
  63. $this->title = strip_tags(input('title', ''), '<a><img>');
  64. $this->fetch();
  65. }
  66. /**
  67. * 语音展示
  68. */
  69. public function voice()
  70. {
  71. $this->url = strip_tags(input('url', ''), '<a><img>');
  72. $this->fetch();
  73. }
  74. /**
  75. * 音乐展示
  76. */
  77. public function music()
  78. {
  79. $this->url = strip_tags(input('url', ''), '<a><img>');
  80. $this->desc = strip_tags(input('desc', ''), '<a><img>');
  81. $this->title = strip_tags(input('title', ''), '<a><img>');
  82. $this->fetch();
  83. }
  84. }